package com.ruoyi.system.service.impl;

import com.ruoyi.system.entity.JobGuarUpdate;
import com.ruoyi.system.mapper.JobGuarUpdateMapper;
import com.ruoyi.system.service.JobGuarUpdateService;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

/**
 * 作业活动监护人变更(JobGuarUpdate)表服务实现类
 *
 * @author makejava
 * @since 2023-06-09 15:58:14
 */
@Service("jobGuarUpdateService")
public class JobGuarUpdateServiceImpl implements JobGuarUpdateService {
    @Resource
    private JobGuarUpdateMapper jobGuarUpdateDao;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public JobGuarUpdate queryById(Integer id) {
        return this.jobGuarUpdateDao.queryById(id);
    }

    /**
     * 分页查询
     *
     * @param jobGuarUpdate 筛选条件
     * @param pageRequest      分页对象
     * @return 查询结果
     */
    @Override
    public Page<JobGuarUpdate> queryByPage(JobGuarUpdate jobGuarUpdate, PageRequest pageRequest) {
        long total = this.jobGuarUpdateDao.count(jobGuarUpdate);
        return new PageImpl<>(this.jobGuarUpdateDao.queryAllByLimit(jobGuarUpdate, pageRequest), pageRequest, total);
    }

    @Override
    public List<JobGuarUpdate> queryAll(JobGuarUpdate jobGuarUpdate) {
        return jobGuarUpdateDao.queryAll(jobGuarUpdate);
    }

    /**
     * 新增数据
     *
     * @param jobGuarUpdate 实例对象
     * @return 实例对象
     */
    @Override
    public JobGuarUpdate insert(JobGuarUpdate jobGuarUpdate) {
        jobGuarUpdate.setCreatedBy("sys");
        jobGuarUpdate.setCreatedDate(new Date());
        this.jobGuarUpdateDao.insert(jobGuarUpdate);
        return jobGuarUpdate;
    }

    /**
     * 修改数据
     *
     * @param jobGuarUpdate 实例对象
     * @return 实例对象
     */
    @Override
    public JobGuarUpdate update(JobGuarUpdate jobGuarUpdate) {
        this.jobGuarUpdateDao.update(jobGuarUpdate);
        return this.queryById(jobGuarUpdate.getId());
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer id) {
        return this.jobGuarUpdateDao.deleteById(id) > 0;
    }
}
